import { T_srv, Tsrv, ifs, ts, tvs, vue } from '@/services';
import { I_cmd, T_cmd } from './command';
import { N_drivingSet } from './type';

const craneParams = (): N_drivingSet.craneParams[] => [
  {
    id: 1,
    actualStation: {
      label: '实工位',
      code: 'my012',
      value: 0
    },
    preStation: {
      label: '预工位',
      code: 'my011',
      value: 0
    },
    workpiece: {
      label: '工件号',
      code: 'my015',
      value: 0
    },
    targetPosition: {
      label: '目标位',
      code: 'my013',
      value: 0
    },
    groupId: {
      label: '挂组ID',
      code: 'my324',
      value: 0
    }
  },
  {
    id: 2,
    actualStation: {
      label: '实工位',
      code: 'my022',
      value: 0
    },
    preStation: {
      label: '预工位',
      code: 'my021',
      value: 0
    },
    workpiece: {
      label: '工件号',
      code: 'my025',
      value: 0
    },
    targetPosition: {
      label: '目标位',
      code: 'my023',
      value: 0
    },
    groupId: {
      label: '挂组ID',
      code: 'my325',
      value: 0
    }
  }
];

const crane1Controls = (): N_drivingSet.ControlState[] => [
  {
    type: 'stop',
    label: '停止',
    btnType: 'error',
    loading: false,
    code: 'my802'
  },
  {
    type: 'release',
    label: '解除',
    btnType: 'success',
    loading: false,
    code: 'my592'
  },
  {
    type: 'pause',
    label: '暂停',
    btnType: 'warning',
    loading: false,
    code: 'my801'
  },
  {
    type: 'start',
    label: '启动',
    btnType: 'primary',
    loading: false,
    code: 'my770'
  }
];

const crane2Controls = (): N_drivingSet.ControlState[] => [
  {
    type: 'stop',
    label: '停止',
    btnType: 'error',
    loading: false,
    code: 'my820'
  },
  {
    type: 'release',
    label: '解除',
    btnType: 'success',
    loading: false,
    code: 'my608'
  },
  {
    type: 'pause',
    label: '暂停',
    btnType: 'warning',
    loading: false,
    code: 'my819'
  },
  {
    type: 'start',
    label: '启动',
    btnType: 'primary',
    loading: false,
    code: 'my771'
  }
];

const cranehookStates = (): N_drivingSet.HookState[][] => [
  [
    {
      type: 'hookA',
      label: '甲钩',
      icon: 'md-link',
      active: true,
      code: 'my872'
    },
    {
      type: 'hookB',
      label: '乙钩',
      icon: 'md-unlink',
      active: false,
      code: 'my873'
    }
  ],
  [
    {
      type: 'hookA',
      label: '甲钩',
      icon: 'md-link',
      active: true,
      code: 'my874'
    },
    {
      type: 'hookB',
      label: '乙钩',
      icon: 'md-unlink',
      active: false,
      code: 'my875'
    }
  ]
];

const tiltSettings = (): N_drivingSet.TiltParams[] => [
  {
    id: 1,
    rise: {
      slowToFastTime: {
        code: 'my178',
        value: 0
      },
      slowKeepTime: {
        code: 'my177',
        value: 0
      },
      angle: {
        code: 'my142',
        value: 0
      },
      startPosition: {
        code: 'my134',
        value: 0
      }
    },
    fall: {
      fastHoldTime: {
        code: 'my176',
        value: 0
      }
    }
  },
  {
    id: 2,
    rise: {
      slowToFastTime: {
        code: 'my174',
        value: 0
      },
      slowKeepTime: {
        code: 'my173',
        value: 0
      },
      angle: {
        code: 'my144',
        value: 0
      },
      startPosition: {
        code: 'my151',
        value: 0
      }
    },
    fall: {
      fastHoldTime: {
        code: 'my172',
        value: 0
      }
    }
  }
];

const advancedSettings = (): N_drivingSet.AdvancedSettings => ({
  priority: {
    crane1: {
      data: Array.from({ length: 5 }, (_, i) => {
        const baseCode = 12 + i * 10;
        return {
          col0: {
            code: `mycDrivingSet${baseCode.toString().padStart(3, '0')}`,
            value: 0
          },
          col1: {
            code: `mycDrivingSet${(baseCode + 1).toString().padStart(3, '0')}`,
            value: 0
          },
          col2: {
            code: `mycDrivingSet${(baseCode + 2).toString().padStart(3, '0')}`,
            value: 0
          },
          col3: {
            code: `mycDrivingSet${(baseCode + 3).toString().padStart(3, '0')}`,
            value: 0
          },
          col4: {
            code: `mycDrivingSet${(baseCode + 4).toString().padStart(3, '0')}`,
            value: 0
          },
          col5: {
            code: `mycDrivingSet${(baseCode + 5).toString().padStart(3, '0')}`,
            value: 0
          },
          col6: {
            code: `mycDrivingSet${(baseCode + 6).toString().padStart(3, '0')}`,
            value: 0
          },
          col7: {
            code: `mycDrivingSet${(baseCode + 7).toString().padStart(3, '0')}`,
            value: 0
          },
          col8: {
            code: `mycDrivingSet${(baseCode + 8).toString().padStart(3, '0')}`,
            value: 0
          },
          col9: {
            code: `mycDrivingSet${(baseCode + 9).toString().padStart(3, '0')}`,
            value: 0
          }
        };
      })
    },
    crane2: {
      data: Array.from({ length: 5 }, (_, i) => {
        const baseCode = 62 + i * 10;
        return {
          col0: {
            code: `mycDrivingSet${baseCode.toString().padStart(3, '0')}`,
            value: 0
          },
          col1: {
            code: `mycDrivingSet${(baseCode + 1).toString().padStart(3, '0')}`,
            value: 0
          },
          col2: {
            code: `mycDrivingSet${(baseCode + 2).toString().padStart(3, '0')}`,
            value: 0
          },
          col3: {
            code: `mycDrivingSet${(baseCode + 3).toString().padStart(3, '0')}`,
            value: 0
          },
          col4: {
            code: `mycDrivingSet${(baseCode + 4).toString().padStart(3, '0')}`,
            value: 0
          },
          col5: {
            code: `mycDrivingSet${(baseCode + 5).toString().padStart(3, '0')}`,
            value: 0
          },
          col6: {
            code: `mycDrivingSet${(baseCode + 6).toString().padStart(3, '0')}`,
            value: 0
          },
          col7: {
            code: `mycDrivingSet${(baseCode + 7).toString().padStart(3, '0')}`,
            value: 0
          },
          col8: {
            code: `mycDrivingSet${(baseCode + 8).toString().padStart(3, '0')}`,
            value: 0
          },
          col9: {
            code: `mycDrivingSet${(baseCode + 9).toString().padStart(3, '0')}`,
            value: 0
          }
        };
      })
    }
  },
  operation: {
    preLiftTime: {
      code: 'my032',
      value: 0
    },
    rectifierLiftDelay: {
      code: 'my033',
      value: 0
    },
    allowExchangeLimit: {
      code: 'my003',
      value: 0
    }
  },
  advanced: {
    crane1: {
      useCardReader: {
        code: 'mycDrivingSet002',
        value: true
      },
      specialMaterialValid: {
        code: 'my794', // 0有效，1无效
        value: true
      },
      codeReadStation: {
        code: 'mySupplement006',
        value: 0
      },
      liftSlow: {
        code: 'mycDrivingSet004',
        value: 0
      },
      liftFast: {
        code: 'mycDrivingSet006',
        value: 0
      },
      positionDelay: {
        code: 'mycDrivingSet010',
        value: 0
      },
      countDetectDelay: {
        code: 'mycDrivingSet001',
        value: 0
      }
    },
    crane2: {
      codeReadStation: {
        code: 'mySupplement006',
        value: 0
      },
      useCardReader: {
        code: 'mycDrivingSet003',
        value: true
      },
      // specialMaterialValid: {
      //   code: 'L54',
      //   value: true
      // },
      liftSlow: {
        code: 'mycDrivingSet005',
        value: 0
      },
      liftFast: {
        code: 'mycDrivingSet007',
        value: 0
      },
      positionDelay: {
        code: 'mycDrivingSet011',
        value: 0
      }
      // countDetectDelay: {
      //   code: 'mycDrivingSet001',
      //   value: 0
      // }
    }
  }
});

// const craneStates = () => [
//   {
//     id: 1,
//     isPaused: {
//       code: 'my801',
//       value: false
//     },
//     isErrSlot: {
//       code: 'my795',
//       value: false
//     },
//     errorSlotNum: {
//       code: 'my018',
//       value: 0
//     },
//     errProcessValue: {
//       code: '',
//       value: 0
//     }
//   },
//   {
//     id: 2,
//     isPaused: {
//       code: 'my001',
//       value: false
//     },
//     isErrSlot: {
//       code: 'my801',
//       value: false
//     },
//     errorSlotNum: {
//       code: 'my018',
//       value: 0
//     },
//     errProcessValue: {
//       code: '',
//       value: 0
//     }
//   }
// ];

export {
  I_cmd,
  N_drivingSet,
  T_cmd,
  T_srv,
  Tsrv,
  advancedSettings,
  crane1Controls,
  crane2Controls,
  craneParams,
  cranehookStates,
  ifs,
  tiltSettings,
  ts,
  tvs,
  vue
};
